import { getnetworkDetail } from '@/api/network'
import { ref } from 'vue'

/**
 * 网点详情服务
 */
export default function () {
  const getNetworkDetailLoading = ref(false)
  const networkDetail = ref<NetworkAPIResponse.NetworkDetail>({
    address: '',
    area: '',
    cancelOrderQty: 0,
    category: 0,
    city: '',
    code: '',
    createTime: '',
    custAccId: '',
    department: [],
    departmentIds: [],
    enableStore: false,
    finishOrderQty: 0,
    handlerOrderQty: 0,
    id: '',
    name: '',
    networkAgency: null,
    networkType: '',
    orderSettlementQty: 0,
    orderWaitSettlementQty: 0,
    province: '',
    shorterName: '',
    status: false,
    storeId: null,
    teamType: 1,
    threeNetworkType: '',
    totalOrderQty: 0,
    town: '',
    twoNetworkType: '',
    type: 0,
    updateTime: '',
  })

  const getNetworkDetail = async (networkId: string) => {
    try {
      getNetworkDetailLoading.value = true
      const res = await getnetworkDetail(networkId)
      getNetworkDetailLoading.value = false
      if (res.data.code === 2000) {
        networkDetail.value = res.data.data.row
        return ''
      }

      return res.data.message
    } catch (error) {
      getNetworkDetailLoading.value = false
      return '获取网点详情失败，请稍后重试'
    }
  }

  return {
    networkDetail,
    getNetworkDetailLoading,
    getNetworkDetail,
  }
}
